//
//  DANetWorkReachabilityStatus.m
//  DAKnowledge
//
//  Created by DreamArts on 16/5/17.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DANetWorkReachabilityStatus.h"

@interface DANetWorkReachabilityStatus ()
@property (nonatomic)BOOL isSuccessful;
@end
@implementation DANetWorkReachabilityStatus

+ (void)netWorkSuccessBlock:(successBlock)success{
    
    [[self sharedManager] startMonitoring];
    [[self sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status == 0) {
            success(@"当前网络不可用");
        } else if(status == 1){
            success(@"正在使用手机流量");
        }else if (status == 2){
            success(@"wifi状态下");
        }
    }];

}

+(BOOL)isNetWorkConnect{
    DANetWorkReachabilityStatus *NetWorkStatus = [[DANetWorkReachabilityStatus alloc]init];
    
    [[self sharedManager] startMonitoring];
    [[self sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status == 0) {
           // success(@"当前网络不可用");
            NetWorkStatus.isSuccessful = NO;
        } else if(status == 1){
           // success(@"正在使用手机流量");
            NetWorkStatus.isSuccessful = YES;
        }else if (status == 2){
           // success(@"wifi状态下");
            NetWorkStatus.isSuccessful = YES;
        }else{
            NetWorkStatus.isSuccessful = NO;
        }
        
        
    }];
    
    return NetWorkStatus.isSuccessful;
}

+ (void)isNetWorkConnectWithBlock:(isNetWorkConnectBlock)block{
    
    [[self sharedManager] startMonitoring];
    [[self sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status == 0) {
            // success(@"当前网络不可用");
            block(NO);
        } else if(status == 1){
            // success(@"正在使用手机流量");
           // NetWorkStatus.isSuccessful = YES;
            block(NO);
        }else if (status == 2){
            // success(@"wifi状态下");
           // NetWorkStatus.isSuccessful = YES;
            block(YES);
        }else{
           // NetWorkStatus.isSuccessful = NO;
            block(NO);
        }
    }];
    [[DANetWorkReachabilityStatus sharedManager] stopMonitoring];
}






@end
